package com.gk.panda.apis.patrol.commons;

import cn.hutool.core.util.NumberUtil;
import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;

/**
 * 地理坐标相关api
 * @Author：xxz
 * @Create: 2022/11/8 18:23
 */
public class GeoUtils {

  public static double getDistanceMeter(GlobalCoordinates gpsFrom, GlobalCoordinates gpsTo, Ellipsoid ellipsoid)
  {
    //创建GeodeticCalculator，调用计算方法，传入坐标系、经纬度用于计算距离
    GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(ellipsoid, gpsFrom, gpsTo);

    return geoCurve.getEllipsoidalDistance();
  }

  /**
   * 计算两点之间的距离
   * @param lon1 起点经度
   * @param lat1 起点纬度
   * @param lon2 终点经度
   * @param lat2 终点纬度
   * @return 距离 单位千米
   */
  public static Double distance(Double lon1, Double lat1, Double lon2, Double lat2){

    GlobalCoordinates source = new GlobalCoordinates(lat1, lon1);
    GlobalCoordinates target = new GlobalCoordinates(lat2, lon2);
//    double div = NumberUtil.div(getDistanceMeter(source, target, Ellipsoid.WGS84), 1000);
    return getDistanceMeter(source, target, Ellipsoid.WGS84);
  }


}
